﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using backoffice.Data;

namespace backoffice.Business
{
    public class BusinessSoil
    {
        #region Create
        public static void createSoil(Soil s)
        {
            try
            {
                dataSoil.createSoil(s);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error creating soil");
            }
        }

        public static void createSoil(Plant p,
                                      float pHMin, float pHMax,
                                      float phosphorusMin, float phosphorusMax,
                                      float nitrogenMin, float nitrogenMax,
                                      float potassiumMin, float potassiumMax)
        {
            try
            {
                Soil s = new Soil();
                s.PlantID = p.PlantID;
                s.pHMin = pHMin;
                s.pHMax = pHMax;
                s.PhosphorusMin = phosphorusMin;
                s.PhosphorusMax = phosphorusMax;
                s.NitrogenMin = nitrogenMin;
                s.NitrogenMax = nitrogenMax;
                s.PotassiumMin = potassiumMin;
                s.PotassiumMax = potassiumMax;

                dataSoil.createSoil(s);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error creating soil");
            }
        }
        #endregion

        #region Get
        public static Soil getSoil(Guid guid)
        {
            try
            {
                return dataSoil.getSoil(guid);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error getting soil");
            }
        }

        public static Soil getSoilByPlant(Plant p)
        {
            try
            {
                return dataSoil.getSoil(p.PlantID);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error getting soil by plant");
            }
        }
        #endregion

        #region Set
        public static Boolean changeSoil(Soil s)
        {
            try
            {
                return dataSoil.changeSoil(s);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error changing soil");
            }
        }
        #endregion

        #region Delete
        public static Boolean deleteSoil(Soil s)
        {
            try
            {
                return dataSoil.deleteSoil(s);
            }
            catch (Exception e)
            {
                Messages.AddDebug(e.Message);
                throw new Exception("Error deleting soil");
            }
        }
        #endregion
    }
}
